import React, { Component } from 'react'
import { connect } from 'react-redux'
class List2 extends Component {
  render() {
    return (
      <div>
        list2222
        <button onClick = { () => {
          this.props.changeList([7,8,9])
        }}>改变数据为 7，8，9</button>
        {
          this.props.list.map((item, index) => (
            <div key = { index }>{ item }</div>
          ))
        }
      </div>
    )
  }
}
// const mapStateToProps = (state) => {
//   return {
//     list: state.list
//   }
// }
// const mapStateToProps = ({ list }) => {
//   return {
//     list
//   }
// }
const mapStateToProps = ({ list }) => ({ list })
const mapDispatchToProps = (dispatch) => {
  return {
    changeList (payload) {
      dispatch({
        type: 'CHANGE_LIST',
        payload
      })
    }
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(List2)